package top.zhaojx.rpc.transport.codec.serializer;

/**
 * 通用的序列化反序列化接口
 */
public interface CommonSerializer {

    byte KRYO_SERIALIZER = 0x1;
    byte HESSIAN_SERIALIZER = 0x2;
    byte PROTOSTUFF_SERIALIZER = 0x3;

    static CommonSerializer getByCode(byte code) {
        switch (code) {
            case KRYO_SERIALIZER:
                return new KryoSerializer();
            case HESSIAN_SERIALIZER:
                return new HessianSerializer();
            case PROTOSTUFF_SERIALIZER:
                return new ProtostuffSerializer();
            default:
                return null;
        }
    }

    byte[] serialize(Object obj);

    <T> T deserialize(byte[] bytes, Class<T> clazz);
}
